// pages/address/address.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      flag: false,
      list: []
  },
  gopay(e) {
      if (this.data.flag) {
          let addresslist = wx.getStorageSync('addresslist');
          let index = e.currentTarget.dataset.index;
          console.log(index);
          wx.setStorageSync('nowaddress', addresslist[index]);
          wx.navigateBack();
      }
  },
  delete(e){
      let index = e.target.dataset.index;
      let addresslist = wx.getStorageSync('addresslist');
      addresslist.splice(index,1);
      wx.setStorageSync('addresslist', addresslist);
      this.setData({
          list:addresslist,
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options.flag);
      if (options.flag) {
          this.setData({
              flag: true,
          })
          console.log(this.data.flag);
      }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      let addresslist = wx.getStorageSync('addresslist');
      this.setData({
          list: addresslist
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})